//
//  GKZYUniversityScoreBarPlotView.m
//  GKZYAid
//
//  Created by Tony Zhang on 16/3/14.
//  Copyright © 2016年 GKZYAid. All rights reserved.
//

#import "GKZYUniversityScoreBarPlotView.h"
#import "MyDefine.h"
#import "GKZYUniversityScoreModel.h"

@implementation GKZYUniversityScoreBarPlotView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}

-(void)configureTheViewWithArray:(NSArray *)array{

    CALayer *verticalLine = [CALayer layer];
    verticalLine.backgroundColor = DeepCustomGrayColor.CGColor;
    verticalLine.frame = CGRectMake(10, 20, 1, 160);
    [self.layer addSublayer:verticalLine];
    
    CALayer *horizontalLine = [CALayer layer];
    horizontalLine.backgroundColor = DeepCustomGrayColor.CGColor;
    horizontalLine.frame = CGRectMake(10, 180, KmainScreenBoundsWidth-20, 1);
    [self.layer addSublayer:horizontalLine];
    NSInteger count = array.count;
    for (int i = 0; i <count; i ++) {
        
        GKZYUniversityScoreModel *model = array[i];
        
        UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake((KmainScreenBoundsWidth-20)/(2*count+1)*(2*i+1)+10, 24, (KmainScreenBoundsWidth-20)/(2*count+1), 156)];
        label1.backgroundColor = CustomGrayColor;
        [self addSubview:label1];
        
        int score = [model.avg_score intValue];
        UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(label1.frame), 24+156-156*score/750, CGRectGetWidth(label1.frame), 156*score/750)];
        label2.backgroundColor = [UIColor orangeColor];
        label2.textColor = [UIColor whiteColor];
        label2.text = [NSString stringWithFormat:@"%d",score];
        label2.textAlignment = NSTextAlignmentCenter;
        [self addSubview:label2];
        
        UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(label1.frame), CGRectGetMaxY(label1.frame)+10, CGRectGetWidth(label1.frame)*1.5, 20)];
        label3.font = [UIFont systemFontOfSize:12];
        NSString *string = [NSString stringWithFormat:@"%@",model.year];
        label3.text = string;
        [self addSubview:label3];
       
    }
    
}



@end
